﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DSPL.Contracts.Common
{
    public static class CommonFunctions
    {
        public static string GetFormatedColumnName(string colName)
        {
            try
            {
                StringBuilder newText = new StringBuilder();
                colName = colName.Trim();

                char[] charArr = colName.ToCharArray();

                newText.Append(char.ToUpper(charArr[0]).ToString());
                for (int i = 0; i < charArr.Length; i++)
                {

                    if (char.IsUpper(charArr[i]) && i > 0 && !char.IsUpper(charArr[i - 1]))
                    {
                        newText.Append(" ");
                        newText.Append(char.ToUpper(charArr[i]).ToString());
                    }
                    else if (char.Equals('_', charArr[i]))
                    {
                        newText.Append(" ");
                        newText.Append(char.ToUpper(charArr[i + 1]).ToString());
                        i += 1;
                    }
                    else if (char.Equals(' ', charArr[i]))
                    {
                        newText.Append(" ");
                        newText.Append(char.ToUpper(charArr[i + 1]).ToString());
                        i += 1;
                    }
                    else
                    {
                        if (i > 0)
                        {
                            newText.Append(charArr[i].ToString());
                        }
                    }
                }

                return newText.ToString();
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
